package io.zcoder.innoway.models;


import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import io.zcoder.innoway.commons.Constants;
import io.zcoder.innoway.utils.Utils;

public class Profile implements Parcelable {

    @SerializedName("id")
    int id;
    @SerializedName("first_name")
    String first_name;
    @SerializedName("last_name")
    String last_name;
    @SerializedName("user_id")
    int user_id;
    @SerializedName("passcode")
    String passcode;
    @SerializedName("height")
    int height;
    @SerializedName("gender")
    int gender;
    @SerializedName("body_type")
    int body_type;
    @SerializedName("birthday")
    String birthday;
    @SerializedName("avatar_url")
    String avatar_url;
    @SerializedName("goal_weight")
    float goal_weight;
    @SerializedName("weight_unit")
    int weight_unit;
    @SerializedName("height_unit")
    int height_unit;
    @SerializedName("age")
    String age;
    @SerializedName("last_used_time")
    String last_used_time;
    @SerializedName("relation")
    int relation;

    @SerializedName("init_weight")
    float initWeight;

    @SerializedName("profession")
    String profession;

    public Profile() {
    }

    protected Profile(Parcel in) {
        id = in.readInt();
        first_name = in.readString();
        last_name = in.readString();
        user_id = in.readInt();
        passcode = in.readString();
        height = in.readInt();
        gender = in.readInt();
        body_type = in.readInt();
        birthday = in.readString();
        avatar_url = in.readString();
        goal_weight = in.readFloat();
        weight_unit = in.readInt();
        height_unit = in.readInt();
        age = in.readString();
        last_used_time = in.readString();
        relation = in.readInt();
        initWeight = in.readFloat();
        profession = in.readString();
    }

    public static final Creator<Profile> CREATOR = new Creator<Profile>() {
        @Override
        public Profile createFromParcel(Parcel in) {
            return new Profile(in);
        }

        @Override
        public Profile[] newArray(int size) {
            return new Profile[size];
        }
    };

    public float getInitWeight() {
        return initWeight;
    }

    public int getProfessionInt() {
        if ("mental-worker".equals(profession)) {
            return 0;
        } else if ("manual-worker".equals(profession)) {
            return 1;
        } else {
            return 2;
        }
    }

    public void setInitWeight(float initWeight) {
        this.initWeight = initWeight;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public int getUser_id() {
        return user_id;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public void setUser_id(int user_id) {
        this.user_id = user_id;
    }

    public String getPasscode() {
        return passcode;
    }

    public void setPasscode(String passcode) {
        this.passcode = passcode;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public int getBody_type() {
        return body_type;
    }

    public void setBody_type(int body_type) {
        this.body_type = body_type;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAvatar_url() {
        if (Utils.isBlank(avatar_url)) {
            return Constants.URL_AVATAR_DEFAULT;
        }
        return avatar_url;
    }

    public void setAvatar_url(String avatar_url) {
        this.avatar_url = avatar_url;
    }

    public float getGoal_weight() {
        return Utils.formatFloat(goal_weight);
    }

    public float getGoalWeight(int unit) {
        float f = goal_weight * Utils.getRatioWeight(unit);
        return Utils.formatFloat(f);
    }

    public String getGoalWeightWithUnit(int unit) {
        return getGoalWeight(unit) + Utils.getUnitWeight(unit);
    }

    public void setGoal_weight(float goal_weight) {
        this.goal_weight = goal_weight;
    }

    public int getWeight_unit() {
        return weight_unit;
    }

    public void setWeight_unit(int weight_unit) {
        this.weight_unit = weight_unit;
    }

    public int getHeight_unit() {
        return height_unit;
    }

    public void setHeight_unit(int height_unit) {
        this.height_unit = height_unit;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getLast_used_time() {
        return last_used_time;
    }

    public void setLast_used_time(String last_used_time) {
        this.last_used_time = last_used_time;
    }

    public int getRelation() {
        return relation;
    }

    public void setRelation(int relation) {
        this.relation = relation;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(first_name);
        dest.writeString(last_name);
        dest.writeInt(user_id);
        dest.writeString(passcode);
        dest.writeInt(height);
        dest.writeInt(gender);
        dest.writeInt(body_type);
        dest.writeString(birthday);
        dest.writeString(avatar_url);
        dest.writeFloat(goal_weight);
        dest.writeInt(weight_unit);
        dest.writeInt(height_unit);
        dest.writeString(age);
        dest.writeString(last_used_time);
        dest.writeInt(relation);
        dest.writeFloat(initWeight);
        dest.writeString(profession);
    }
}
